package com.garbuz.svnadmin.data
{
	import actionlib.common.query.conditions.equals;
	import actionlib.common.query.from;

	import com.garbuz.svnadmin.dto.UserTO;

	import mx.collections.ArrayCollection;

	public class User
	{
		public static function fromTO(data:UserTO):User
		{
			var user:User = new User();
			user.name = data.name;
			user.hash = data.hash;
			user.groupNames = new ArrayCollection(from(data.groupNames).select());
			return user
		}
		
		[Bindable]
		public var name:String;
		
		[Bindable]
		public var hash:String;
		
		[Bindable]
		public var groupNames:ArrayCollection;

		public function get label():String
		{
			return name;
		}

		public function hasGroup(groupName:String):Boolean
		{
			return from(groupNames).where(equals(groupName)).exists();
		}
	}
}